package com.personal.website.lottery.web.controller;

import com.personal.website.lottery.web.service.ArticleService;
import com.personal.website.lottery.web.service.DoubleColorBallService;
import com.personal.website.lottery.web.util.TableRecordsGenerate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Gavin on 2016/2/16.
 */
@Controller
@RequestMapping("/page")
public class PageController {

    @Resource
    private DoubleColorBallService doubleColorBallService;
    @Resource
    private ArticleService articleService;

    @RequestMapping("/chartDes")
    public String chartDes() {
        return "chartDes";
    }

    @RequestMapping("/selectNumber")
    public String selectNumber(Model model) {
        return "selectNumber";
    }

    @RequestMapping("/other")
    public String other() {
        return "other";
    }

    @RequestMapping("/articles")
    public String articles(Model model) {
        model.addAttribute("articles",this.articleService.getArticles(30));
        return "articles";
    }

    @RequestMapping("/restForTableData")
    @ResponseBody
    public String restForTableData(HttpServletRequest request){
        String tableName = request.getParameter("tableName");
        TableRecordsGenerate generate = new TableRecordsGenerate(this.doubleColorBallService);
        if("MainTable".equals(tableName)) {
            return generate.generateMainTableRecords();
        } else if("BlueTable".equals(tableName)) {
            return generate.generateBlueTableRecords();
        } else if("EightDigitTable".equals(tableName)) {
            return generate.generateEightDigitTableRecords();
        } else if("ElevenDigitTable".equals(tableName)) {
            return generate.generateElevenDigitTableRecords();
        } else if("End3dTable".equals(tableName)) {
            return generate.generateEnd3dTableRecords();
        } else if("EndTable".equals(tableName)) {
            return generate.generateEndTableRecords();
        } else if("EvenTable".equals(tableName)) {
            return generate.generateEvenTableRecords();
        } else if("FourPart012Table".equals(tableName)) {
            return generate.generateFourPart012TableRecords();
        } else if("FourPartEnd012Table".equals(tableName)) {
            return generate.generateFourPartEnd012TableRecords();
        } else if("OddTable".equals(tableName)) {
            return generate.generateOddTableRecords();
        } else {
            return "Not Correct Table Name";
        }
    }
}